from flask import Blueprint,request,jsonify

import datetime

from utils.db import db1

from comm import get_data

message_bp = Blueprint('mes',__name__)

@message_bp.route('/getcategory')
def getcategory():
    sql = "select * from category"

    res = db1.find_all(sql)

    return jsonify({'code':200,'list':res})



@message_bp.route('/addmessage',methods=["POST"])
def addmessage():
    data = get_data()

    print(data)

    sql = "insert into message(id,title,content,status,category,times,proiority,notice) values(0,'%s','%s','%s',%d,'%s','%s')" % (data['title'],data['content'],data['status'],int(data['category']),str(data['time']),str(data['proiority'],data['notice']))

    db1.update(sql)

    return 'ok'




# 获取所有用户

@message_bp.route('/getmesuser')
def getmesusers():
    sql = "select id,name,gender from users"

    res = db1.find_all(sql)

    return jsonify({'code':200,'list':res})


















